<template>
	<view>
		<image src="/static/personal/topbg.png" class="topbg" mode="widthFix"></image>
		<u-loading-page :loading="loading"></u-loading-page>
		<view class="con" v-if="!loading">
			<view class="info">
				<image :src="URL(userinfo.avatar)" class="info__tx" mode="aspectFill"></image>
				<view class="u-flex u-flex-column u-flex-center" style="margin-left: 22rpx;">
					<view class="info__name">
						{{userinfo.username}}
					</view>
					<view class="info__yq">
						邀请码:{{userinfo.salt}}
						<image src="/static/personal/fz.png" class="info__yq__fz" mode="" @click="copy(userinfo.salt)">
						</image>
					</view>
				</view>
			</view>
			<view class="box" v-if="userinfo.group_id==1">
				<view class="box__title" style="padding-left: 25rpx;">
					我的服务
				</view>
				<view class="box__list">
					<view class="box__list__item" v-for="(item,index) in baseList" :key="index"
						@click="navto('/pages/personal/'+item.url)">
						<image :src="item.name" class="box__list__item__icon" mode=""></image>
						<view class="box__list__item__text">
							{{item.title}}
						</view>
					</view>
				</view>
			</view>
			<view class="box" v-else style="height: 221rpx;display: flex;align-items: center;"
				@click="navto('/pages/tool/workstatistics')">
				<view class="box__x">
					<view class="box__x__num">
						{{tjinfo.newCustomer}}
					</view>
					<view class="box__x__text">
						新增客户
					</view>
				</view>
				<view class="box__x">
					<view class="box__x__num">
						{{tjinfo.totalCustomer}}
					</view>
					<view class="box__x__text">
						客户总数
					</view>
				</view>
				<view class="box__x">
					<view class="box__x__num">
						{{tjinfo.contractCustomer}}
					</view>
					<view class="box__x__text">
						联系客户
					</view>
				</view>
				<view class="box__x">
					<view class="box__x__num">
						{{tjinfo.visitCount}}
					</view>
					<view class="box__x__text">
						拜访
					</view>
				</view>
			</view>
			<!-- <view class="box" style="height: 221rpx;" v-if="userinfo.group_id==1">
				<view class="box__title" style="padding-left: 25rpx;">
					租赁订单
					<view class="u-flex u-flex-y-center" @click="navto('/pages/lease/order')">
						<text style="color: #919191;font-size: 22rpx;margin-right: 11rpx;">全部</text>
						<image src="/static/personal/more1.png" style="width: 11rpx;height: 19rpx;" mode=""></image>
					</view>

				</view>
				<view class="box__list">
					<view class="box__list__item" v-for="(item,index) in baseList1" :key="index"
						@click="navto('/pages/lease/order')">
						<image :src="item.name" class="" :style="{width:item.w,height:item.h}" mode=""></image>
						<view class="box__list__item__text" style="margin-top: 16rpx;">
							{{item.title}}
						</view>
					</view>
				</view>
			</view> -->
			<view class="box1">
				<view class="box__title" style="padding-left: 25rpx;">
					更多功能
				</view>
				<view class="box1__list">
					<view class="box1__list__item" v-for="(item,index) in list" :key="index" @click="clickto(item.url)">
						<view class="box1__list__item__iconbox">
							<image :src="item.icon" class="box1__list__item__iconbox__icon"
								:style="{width:item.w,height:item.h}" mode=""></image>
						</view>
						<view class="box1__list__item__text u-flex u-flex-y-center u-flex-between"
							:class="index==(list.length-1)?'bb0':''">
							{{item.text}}
							<image src="/static/personal/more2.png" style="width: 12rpx;height: 22rpx;" mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<tabbar :current="current"></tabbar>
	</view>
</template>

<script>
	import CryptoJS from 'crypto-js';
	import user from '@/api/_user.js'
	import sale from '@/api/_sale.js'
import { data, methods } from '../../uni_modules/uview-ui/libs/mixin/mixin';
	export default {
		data() {
			return {
				loading: true,
				current: 1,
				baseList: [{
						name: '/static/personal/wddk.png',
						title: '我的贷款',
						url: 'daikuan'
					},
					// {
					// 	name: '/static/personal/fxzx.png',
					// 	title: '分销中心',
					// 	url: 'fxzx'
					// }, {
					// 	name: '/static/personal/wdqb.png',
					// 	title: '我的钱包',
					// 	url: 'wallet'
					// },
					{
						name: '/static/personal/wdzl.png',
						title: '我的资料',
						url: 'infomation'
					}
				],
				baseList1: [{
					name: '/static/personal/dfk.png',
					title: '待付款',
					w: '49rpx',
					h: '49rpx'
				}, {
					name: '/static/personal/dfh.png',
					title: '待发货',
					w: '55rpx',
					h: '53rpx'
				}, {
					name: '/static/personal/fsh.png',
					title: '待收货',
					w: '50rpx',
					h: '50rpx'
				}, {
					name: '/static/personal/dgh.png',
					title: '待归还',
					w: '55rpx',
					h: '53rpx'
				}],
				list: [{
						icon: '/static/personal/sfyz.png',
						text: '身份验证',
						w: '41rpx',
						h: '34rpx',
						url: 'verify'
					},

					{
						icon: '/static/personal/set.png',
						text: '我的设置',
						w: '37rpx',
						h: '36rpx',
						url: 'set'
					},
				],
				userinfo: {},
				list2: [{
						icon: '/static/personal/sfyz.png',
						text: '个人资料',
						w: '41rpx',
						h: '34rpx',
						url: 'infomation'
					},
					{
						icon: '/static/personal/xssq.png',
						text: '在线签约',
						w: '37rpx',
						h: '44rpx',
						url: 'contract'
					},
					{
						icon: '/static/personal/set.png',
						text: '我的设置',
						w: '37rpx',
						h: '36rpx',
						url: 'set'
					},
				],
				list3: [{
						icon: '/static/personal/sfyz.png',
						text: '个人资料',
						w: '41rpx',
						h: '34rpx',
						url: 'infomation'
					},
					{
						icon: '/static/personal/kh.png',
						text: '意向客户',
						w: '37rpx',
						h: '34rpx',
						url: 'khlist'
					},
					{
						icon: '/static/personal/xssq.png',
						text: '在线签约',
						w: '37rpx',
						h: '44rpx',
						url: 'contract'
					},
					{
						icon: '/static/personal/set.png',
						text: '我的设置',
						w: '37rpx',
						h: '36rpx',
						url: 'set'
					}
				],
				tjinfo: {},
				appKey: '93b6713b-9d22-4f76-ae07-1eba2896617a',
				SecretKey: '66343533323861612d633237372d346362392d383435642d623966646365366433623866',
				signurl: 'https://testapi.zhongzhizhengxin.com:9998/api/open'
			}
		},
		methods: {
			async getuser() {
				let res = await user.userindex()
				this.userinfo = res.data.data
				uni.setStorageSync('dkuserinfo', this.userinfo)
				if (this.userinfo.group_id == 3) {
					this.list = this.list2
					this.gettj()
				}
				if (this.userinfo.group_id == 2) {
					this.list = this.list3
					this.gettj()
				}
				this.loading = false
			},
			async gettj() {
				let res = await sale.myWork()
				if (res.data.code == 1) {
					this.tjinfo = res.data.data

				}
			},
			clickto(url) {
				if (url == "contract") {

					
					// 生成签名
					let timestamp = new Date().getTime()
					let appKey = this.appKey
					let Query = {
						"businessId": "148986b7-422b-4bde-a3a8-4f7fa6f174e4",
						"itemId": "1714214281999331329",
						"certificateMethod": "ELECTRONIC",
						"notarizationNumber": 2,
						"materialList": [{
							"id": "1550055699147300867",
							"value": "最高额抵押合同"
						}, {
							"id": "1548999434145034250",
							"value": "https://test.zhongzhizhengxin.com:9998/api/file/download/1592822161333628929"
						}, {
							"id": "1548999434019205121",
							"value": "不动产权地址"
						}, {
							"id": "1536584269093097488",
							"value": "123456789"
						}, {
							"id": "1536584269093097489",
							"value": "单独所有"
						}, {
							"id": "1536584269093097491",
							"value": "https://test.zhongzhizhengxin.com:9998/api/file/download/1592822161333628929"
						}, {
							"id": "1536584269093097492",
							"value": "https://test.zhongzhizhengxin.com:9998/api/file/download/1592822161333628929"
						}, {
							"id": "1550055699147300866",
							"value": "借款合同"
						}, {
							"id": "1548999434145034247",
							"value": "https://test.zhongzhizhengxin.com:9998/api/file/download/159282216133362892"
						}, {
							"id": "1852235145280561155",
							"value": "还款承诺书"
						}, {
							"id": "1777208804762554369",
							"value": "100000"
						}, {
							"id": "1777208804762554370",
							"value": "年利率为0.3%"
						}, {
							"id": "1777208804762554371",
							"value": "2024-04-07"
						}, {
							"id": "1777208804762554372",
							"value": "2025-04-07"
						}, {
							"id": "1852235145280561154",
							"value": "12"
						}, {
							"id": "1777208804762554374",
							"value": "等额本息"
						}],
						"litigantList": [{
							"type": "NON_NATURAL",
							"role": "CREDITOR",
							"name": "债权人",
							"identityNumber": "9100000000000",
							"address": "债权人地址"
						}, {
							"type": "NATURAL",
							"role": "OBLIGOR,MORTGAGOR",
							"name": "张三",
							"identityNumber": "511226199602050035",
							"identityCardFront": "https://test.zhongzhizhengxin.com:9998/api/file/download/1592822161333628929",
							"identityCardBack": "https://test.zhongzhizhengxin.com:9998/api/file/download/1592822161333628929",
							"contact": "13333333333",
							"contactAddress": "测试联系地址"
						}],
						"backUrl": "http://www.baidu.com"
					}
					let SecretKey = this.SecretKey
					let o=appKey+'\n'+timestamp+'\n'+'method=uploadInfo'+'\n'+JSON.stringify(Query)+'\n'+SecretKey
					let sign = CryptoJS.MD5(o).toString()
					uni.showLoading({
						title: "生成签约信息中...."
					})
					uni.request({
						url: this.signurl+'?method=uploadInfo',
						header: {
							timestamp,
							appKey,
							'Content-Type':'application/json',
							sign
						},
						method:'POST',
						data:Query,
						success(r){
							console.log(r.data.message)
							if(r.data.code=='SUCCESS'){
								uni.$u.toast('业务上传成功')
							}else{
								uni.$u.toast('业务上传失败')
							}
						}
					})
					uni.hideLoading()
					return false
				}
				if (url == 'loginout') {
					uni.showModal({
						title: '提示',
						content: '确定要退出登录？',
						success(r) {
							if (r.confirm) {
								uni.removeStorageSync('dkuserinfo')
								uni.removeStorageSync('dktoken')
								uni.reLaunch({
									url: '/pages/index/login'
								})
							}
						}
					})
				} else {
					this.navto('/pages/personal/' + url)
				}
			},

		},
		onLoad() {
			uni.hideTabBar()
			if (uni.getStorageSync('tabBarList').length == 3) {
				this.current = 2
			}

		},
		onShow() {
			this.getuser()
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f8f8f8;
	}

	.topbg {
		width: 750rpx;
		position: fixed;
		top: 0;
		left: 0;
	}

	.con {
		position: relative;
		padding: 164rpx 30rpx 50rpx;

		.info {
			display: flex;
			align-items: center;
			margin-bottom: 43rpx;

			&__tx {
				width: 119rpx;
				height: 119rpx;
				border-radius: 50%;
			}

			&__name {
				font-family: PingFang SC;
				font-weight: 800;
				font-size: 36rpx;
				color: #010101;
				line-height: 34rpx;
				margin-bottom: 23rpx;
			}

			&__yq {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: rgba(0, 0, 0, .7);
				line-height: 26rpx;
				display: flex;
				align-items: center;

				&__fz {
					width: 22rpx;
					height: 23rpx;
					margin-left: 7rpx;
				}
			}
		}
	}

	.box {
		height: 242rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
		margin-bottom: 32rpx;

		&__x {
			width: 25%;
			text-align: center;

			&__num {
				font-family: DIN Next LT Pro;
				font-weight: 500;
				font-size: 48rpx;
				color: #010101;
				line-height: 34rpx;
			}

			&__text {
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 22rpx;
				color: #727475;
				line-height: 22rpx;
				margin-top: 29rpx;
			}
		}

		&__title {
			font-family: PingFang SC;
			font-weight: bold;
			font-size: 28rpx;
			color: #000000;
			line-height: 88rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 20rpx;
		}

		&__list {
			display: flex;
			align-items: center;

			&__item {
				width: 25%;
				display: flex;
				flex-direction: column;
				align-items: center;

				&__icon {
					width: 69rpx;
					height: 71rpx;
					margin-bottom: 17rpx;

				}

				&__text {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 22rpx;
					color: #000000;
					line-height: 22rpx;
				}
			}
		}
	}

	.box1 {
		background: #FFFFFF;
		border-radius: 20rpx;

		&__list {
			&__item {
				display: flex;
				align-items: center;
				height: 130rpx;

				&__iconbox {
					width: 92rpx;
					display: flex;
					justify-content: flex-end;

					&__icon {
						margin-right: 20rpx;

					}
				}

				&__text {
					flex: 1;
					height: 130rpx;
					padding-right: 36rpx;
					border-bottom: 1rpx solid #ECECEC;
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 24rpx;
					color: #212121;
				}
			}
		}
	}

	.bb0 {
		border-bottom: 0 !important;
	}
</style>